package com.doge.walknovel.business.home.discover.viewholders

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.doge.wnpro.R
import com.doge.walknovel.api.model.NovelInfo
import com.doge.walknovel.business.home.discover.BOOK_CLICKED
import com.doge.walknovel.core.base.adapters.AdapterCallback
import com.doge.wnpro.databinding.CellDiscoverGridBinding
import com.doge.walknovel.utils.*

class DiscoverGridViewHolder(
    parent: ViewGroup,
    callback: AdapterCallback,
    private val binding: CellDiscoverGridBinding = CellDiscoverGridBinding.inflate(
        LayoutInflater.from(parent.context), parent, false),
) : RecyclerView.ViewHolder(binding.root) {
    init {
        itemView.setOnClickCallback { callback.invoke(BOOK_CLICKED, itemView.tag) }
        binding.item.setOnClickCallback { callback.invoke(BOOK_CLICKED, itemView.tag) }
    }

    fun bind(item: NovelInfo) {
        itemView.tag = item
        binding.cover.load(
            item.coverUrl,
            R.drawable.shape_f7f7f7_8,
            transformation = RoundedCorners8,
            width = 100.dp,
            height = 143.dp,
        )
        binding.name.text = item.title
        binding.author.text = item.author
    }
}